﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">
    var savedsetting = {
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: null
        }
    };

    function initUserTreeLeft_wfspqxmng() {
        $.ajax({
            url: "/Home/getDeptUserCheckTree",
            type: "POST",
            data: { "nocheck": "false" },
            success: function(Nodes) {
                setting.callback.onCheck = onUsertreeLeftCheck_wfspqxmng;
                $.fn.zTree.init($("#tree_user_left"), setting, eval(Nodes));
            }
        });
    }
    function onUsertreeLeftCheck_wfspqxmng(event, treeId, treeNode) {
        //alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked);
        var user_id = treeNode.id;
        $("#cur_user_id").attr("value", user_id);
        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoGetWFSpaxList",
            data: { "spqx_id": "", "user_id": user_id },
            success: function(Nodes) {
                setting.callback.onCheck = onSpaxrtreeRightCheck_wfspqxmng;
                $.fn.zTree.init($("#tree_spqx_right"), setting, eval(Nodes));
            }
        })
    };
    function onSpaxrtreeRightCheck_wfspqxmng(event, treeId, treeNode) {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo_wfstart");
        var nodes = treeObj.getCheckedNodes(true);

        var temp = "";
        for (i = 0; i < nodes.length; i++) {
            temp = temp + nodes[i].id + ",";
        }
        $("#selectarr").attr("value", temp);
    }
    function saveYhmng() {
        var cur_user_id = $("#cur_user_id").val();
        var new_spqx_ids = $("#new_spqx_ids").val();
        if (cur_user_id == null || cur_user_id == "") {
            alert("未选着一个用户");
            return;
        }

        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoSaveWfSpqxByUserId",
            data: { "spqx_ids": new_spqx_ids, "user_id": cur_user_id },
            success: function(restag) {
                if (restag.res) {
                    alert("操作成功");
                }
                else {
                    alert("操作失败");
                }
            }
        })
    }



    function initSpqxTreeLeft_wfspqxmng() {
        $.ajax({
            url: "/Home/getWfSpqxCheckTree",
            type: "POST",
            data: { "nocheck": "false" },
            success: function(Nodes) {
                setting.callback.onClick = onSpaxrtreeLeftClick_wfspqxmng;
                $.fn.zTree.init($("#tree_spqx_left"), setting, eval(Nodes));
            }
        });
    }
    function onSpaxrtreeLeftClick_wfspqxmng(event, treeId, treeNode) {
        //alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked);
        var spqx_id = treeNode.id;
        $("#cur_spqx_id").attr("value", treeNode.id);
        $("#new_user_ids").attr("value", "");
        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoGetWFSpaxTreeBySpqxId",
            data: { "spqx_id": spqx_id },
            success: function(Nodes) {
                setting.callback.onCheck = onUsertreeRightCheck_wfspqxmng;
                $.fn.zTree.init($("#tree_user_right"), setting, eval(Nodes));
            }
        })
    };
    function onUsertreeRightCheck_wfspqxmng(event, treeId, treeNode) {
        var treeObj = $.fn.zTree.getZTreeObj("tree_user_right");
        var nodes = treeObj.getCheckedNodes(true);
        
        var temp = "";
        for (i = 0; i < nodes.length; i++) {
            //alert(nodes[i].tag);
            if (nodes[i].tag == "用户") {
                temp = temp + nodes[i].id + ",";
            }
        }
        $("#new_user_ids").attr("value", temp);
    }
    function saveQxmng() {
        var cur_spqx_id = $("#cur_spqx_id").val();
        var new_user_ids = $("#new_user_ids").val();
        if (cur_spqx_id == null || cur_spqx_id == "") {
            alert("未选着一个权限");
            return;
        }

        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoSaveWfSpqxBySpqxId",
            data: { "spqx_id": cur_spqx_id, "user_ids": new_user_ids },
            success: function(restag) {
                if (restag.res) {
                    alert("操作成功");
                }
                else {
                    alert("操作失败");
                }
            }
        })
    }

    $(function() {
        initSpqxTreeLeft_wfspqxmng();
    })
</script>

<div id="wfspqxmng">
    <%-- <div>
        <input type="button" value="用户数" onclick="initYhTree()" />
        <input type="button" value="权限树" onclick="initQxTree()" />
    </div>--%>
    <%--   <div id="yhmng" style="display: none">
        <div>
            <input type="hidden" id="cur_user_id" />
            <input type="hidden" id="new_spqx_ids" />
            <div style="float: left;">
                <ul id="tree_user_left" class="ztree" style="height: 230px; width: 260px; float: left;">
                </ul>
            </div>
        </div>
        <ul id="tree_spqx_right" class="ztree" style="height: 230px; width: 260px; float: left;">
        </ul>
        <div>
        </div>
    </div>--%>
    <div id="qxmng">
        <div>
            <div>
                <input type="button" value="保存" onclick="saveQxmng()" />
            </div>
            <input type="hidden" id="cur_spqx_id" />
            <input type="hidden" id="new_user_ids" />
            <div style="padding-left: 20px; padding-top: 50px;">
                <ul id="tree_spqx_left" class="ztree" style="height: 230px; width: 260px; float: left;">
                </ul>
            </div>
        </div>
        <div>
            <div style="">
                <ul id="tree_user_right" class="ztree" style="height: 230px; width: 260px; float: left;">
                </ul>
            </div>
        </div>
    </div>
</div>
<%--
<ol id="selectable">
	<li class="ui-widget-content">Item 1</li>
	<li class="ui-widget-content">Item 2</li>
	<li class="ui-widget-content">Item 3</li>
	<li class="ui-widget-content">Item 4</li>
	<li class="ui-widget-content">Item 5</li>
	<li class="ui-widget-content">Item 6</li>
</ol>--%>